package com.yan.student.controller;

import com.yan.student.dao.StuDao;
import com.yan.student.domain.Student;
import com.yan.student.service.StudentServicelmpl;

import java.util.Scanner;

public class StudentIndex{
    public static final Scanner INPUT = new Scanner(System.in);

    public static final StudentServicelmpl STU = new StudentServicelmpl();

    public static void main(String[] args) {
        outer:
        while (true) {
            System.out.println("--------欢迎来到学生管理系统--------");
            System.out.println("1 添加学生");
            System.out.println("2 删除学生");
            System.out.println("3 修改学生");
            System.out.println("4 查看学生");
            System.out.println("5 退出");
            System.out.println("请输入您的选择:");

            int choice = INPUT.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入学号");
                    String sid = INPUT.next();
                    int index = STU.getIndex(sid);
                    if(index != -1 & StuDao.studentsList.size() != 0){
                        System.out.println("该学号已存在,请重新输入");
                        return;
                    }
                    System.out.println("请输入学生姓名");
                    String name = INPUT.next();
                    System.out.println("请输入学生年龄");
                    int age = INPUT.nextInt();
                    System.out.println("请输入学生居住地");
                    String address = INPUT.next();
                    Student stu = new Student(sid , name , age , address);
                    STU.addStudent(stu);
                    break;
                case 2:
                    System.out.println("请输入要删除的学号");
                    String id = INPUT.next();
                    STU.deletDate(id);
                    break;
                case 3:
                    System.out.println("请输入要修改的学号");
                    String Uid = INPUT.next();
                    STU.upDate(Uid);
                    break;
                case 4:
                    STU.findStudent();
                    break;
                case 5:
                    System.out.println("系统退出");
                    break outer;

            }
        }
    }
}
